package com.cy.lib.executor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author CY
 * @title 线程池处理类
 * @date 2015/7/20
 * @qq 568305883
 * @email tmxdyf@163.com
 */
public class Executor {

    private static ExecutorService mThreadPool;
    private static ExecutorService mSingleThreadPool;

    public synchronized static ExecutorService getThreadPool() {
        if (mThreadPool == null || mThreadPool.isShutdown()) {
            return mThreadPool = Executors.newCachedThreadPool();
        }
        return mThreadPool;
    }

    public synchronized static ExecutorService getSingleThreadPool() {
        if (mSingleThreadPool == null || mSingleThreadPool.isShutdown()) {
            return mSingleThreadPool = Executors.newSingleThreadExecutor();
        }
        return mSingleThreadPool;
    }
}
